﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Windows;
using DemoModule.Views;
using WPF60.Infrastructure.CabSupport;
using WPF60.Infrastructure.Services;

namespace WPF60.DemoModule.Views.HelicopterIntro
{

    public class CoolIntroPresenter : PresenterBase<ICoolWpfView, ICoolIntroViewModel>, IWillNotBeContained
    {
        private readonly IMeetingTimeProvider _meetingTimeProvider;

        public CoolIntroPresenter(IMeetingTimeProvider meetingTimeProvider)
        {
            _meetingTimeProvider = meetingTimeProvider;
        }

        public override void Setup()
        {
            base.Setup();
            SetupTimer();

        }

        void SetupTimer()
        {

            var timer = new System.Timers.Timer();

            timer.Elapsed += (sender, args) =>
                                 {
                                     var timeLeft = _meetingTimeProvider.MeetingTime - DateTime.Now;

                                     View.Dispatcher.BeginInvoke(
                                         new Action(() => ViewModel.TimeToGo = timeLeft)
                                         );
                                 };

            timer.Enabled = true;
            timer.Start();
         
        }

    }
}
